﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using Hardanger.Model;
using System.Windows.Threading;

namespace Hardanger.ViewModel
{
    public class SessionManager
    {
		private Dispatcher _callingDispatcher;
        public Dispatcher CallingDispatcher
        {
            get
            {
                return _callingDispatcher;
            }
        }

        // Nobody should create instances of this class but it cannot be static since we are implementing an interface
        private SessionManager()
        {
			_callingDispatcher = Dispatcher.CurrentDispatcher;
        }

        private HardangerSession _SelectedSession = new HardangerSession();
        public HardangerSession SelectedSession
        {
            get { return _SelectedSession; }
			set {				
				_SelectedSession = value;
			}
        }

		private ObservableCollection<HardangerSession> _AllSessions = new ObservableCollection<HardangerSession>();
		public ObservableCollection<HardangerSession> AllSessions
        {
            get { return _AllSessions; }
        }

        private static SessionManager _current = null;
        public static SessionManager Current
        {
            get 
            {
                if (_current == null)
                {
                    _current = new SessionManager();
                }
                return _current; 
            }
        }

        public void AddSession(HardangerSession session)
        {
			_callingDispatcher.BeginInvoke((System.Action) delegate { _AllSessions.Add(session); });
        }     
    }
}
